<template>
  <el-upload class="upload-demo" action="https://qw.ccpluss.com/common/upload" :limit="1" :file-list="FileList"
    :on-success="handleFileSuccess(value)" :on-remove="handleRemoveFile(value)">
    <el-button size="small" type="primary">点击上传</el-button>
  </el-upload>
</template>

<script>
export default {
  props: {
    form: {
      type: Object,
      default: function () {
        return {};
      },
    },
    value: {
      type: String,
      default: "",
    },
    type: {
      type: String,
      default: "",
    },
  },
  data() {
    return {};
  },
  computed: {
    FileList() {
      // console.log(this.form);
      // console.log(this.value);
      return this.form[this.value] && this.form[this.value].length
        ? [
          {
            name: this.form[this.value].substring(
              this.form[this.value].lastIndexOf("/") + 1
            ),
            url: "https://qw.ccpluss.com" + this.form[this.value],
          },
        ]
        : [];
    },
  },
  created() { },
  mounted() { },
  watch: {},
  methods: {
    // 上传文件
    handleFileSuccess(value) {
      return (response, file) => {
        // console.log(response, "ceshishangchuan");
        this.$emit("ChangeFile", {
          fileRaw: URL.createObjectURL(file.raw),
          value: value,
          file: response.msg,
        });
      };
    },
    // 删除文件
    handleRemoveFile(value) {
      return (response, file) => {
        // console.log(response, file);
        this.$emit("DelFile", {
          value: value,
        });
      };
    },
  },
  components: {},
};
</script>

<style scoped lang="less">
.avatar {
  width: 120px;
  height: 120px;
  display: block;
}
</style>
